// This File is part of the "nyaqt" Project
// 
// Copyright  2009 sometmes@gmail.com
// All rights reserved
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

namespace ResourceCompare
{
    class ResXElement : IComparable<ResXElement>
    {
        string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        object _value;

        public object Value
        {
            get { return _value; }
            set { _value = value; }
        }

        public ResXElement(string name, object value)
        {
            _name = name;
            _value = value;
        }

        bool _original;

        public bool Original
        {
            get { return _original; }
            set { _original = value; }
        }

        public int CompareTo(ResXElement other)
        {
            return this.Name.CompareTo(other.Name);
        }
    }

    class ResXCompareElement
    {
        ResXElement _left; 
        ResXElement _right;

        public ResXCompareElement(ResXElement left, ResXElement right)
        {
            _left = left;
            _right = right;
        }

        public string Name
        {
            get
            {
                return _left.Name;
            }
        }

        IList<ResXElement> _leftList;

        internal IList<ResXElement> LeftList
        {
            get { return _leftList; }
            set { _leftList = value; }
        }

        IList<ResXElement> _rightList;

        internal IList<ResXElement> RightList
        {
            get { return _rightList; }
            set { _rightList = value; }
        }

        public object LeftValue
        {
            get
            {
                return _left.Value;
            }

            set
            {
                if (_left.Value == null)
                    _leftList.Add(_left);
                if (value == null)
                    _leftList.Remove(_left);

                _left.Value = value;
            }
        }

        public object RightValue
        {
            get
            {
                return _right.Value;
            }

            set
            {
                if (_right.Value == null)
                    _rightList.Add(_right);
                if (value == null)
                    _rightList.Remove(_right);

                _right.Value = value;
            }
        }

        HasBaseEnum _hasBase = HasBaseEnum.Unknown;

        public HasBaseEnum HasBase
        {
            get { return _hasBase; }
            set { _hasBase = value; }
        }

        public static bool IsInteresting(ResXCompareElement xe)
        {
            if (xe.HasBase == HasBaseEnum.HasBase && xe.LeftValue == null)
                return true;
            else if (xe.HasBase == HasBaseEnum.NoBase && xe.LeftValue != null)
                return true;
            else if (xe.LeftValue == null && xe.RightValue != null)
                return true;
            else if (xe.LeftValue != null && xe.RightValue == null)
                return true;

            return false;
        }
    }

    public enum HasBaseEnum
    {
        NoBase = 0,
        HasBase = 1,
        Unknown = 99
    }
}


